package com.hgxd.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hgxd.annotation.OperationLogAnnotation;
import com.hgxd.entity.vo.RobotMeasurePointPoVo;
import com.hgxd.result.Result;
import io.netty.util.internal.StringUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;


import com.hgxd.service.IRobotMeasurePointService;
import com.hgxd.entity.RobotMeasurePoint;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 测点表 前端控制器
 * </p>
 *
 * @author wtf
 * @since 2023-12-01
 */
@Api(tags = "机器人测点表")
@RestController
@RequestMapping("/api/robot-measure-point")
public class RobotMeasurePointController {
    @Resource(name = "RobotMeasurePointServiceImpl")
    private IRobotMeasurePointService robotMeasurePointService;

    /**
     * 新增
     */
    @PostMapping("/save")
    @ApiOperation(value = "新增", notes = "无需传入id")
    @ApiImplicitParam(name = "robotMeasurePoint", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人测点表-新增", operType = "新增", operContent = "新增")
    public Result<Boolean> insert(@RequestBody RobotMeasurePoint robotMeasurePoint) {
        robotMeasurePoint.setUpdateTime(LocalDateTime.now());
        return Result.ok(robotMeasurePointService.save(robotMeasurePoint));
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改", notes = "必须传入id")
    @ApiImplicitParam(name = "robotMeasurePoint", value = "实体类")
    @OperationLogAnnotation(operModule = "机器人测点表-修改", operType = "修改", operContent = "修改")
    public Result<Boolean> update(@RequestBody RobotMeasurePoint robotMeasurePoint) {
        robotMeasurePoint.setUpdateTime(LocalDateTime.now());
        return Result.ok(robotMeasurePointService.updateById(robotMeasurePoint));
    }

    /**
     * 根据id删除
     */
    @PostMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除", notes = "必须传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人测点表-根据id删除", operType = "删除", operContent = "根据id删除")
    public Result<Boolean> delete(@PathVariable Integer id) {
        return Result.ok(robotMeasurePointService.removeById(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("/del/batch")
    @ApiOperation(value = "批量删除", notes = "传入ids")
    @ApiImplicitParam(name = "ids", value = "id的数组")
    @OperationLogAnnotation(operModule = "机器人测点表-批量删除", operType = "删除", operContent = "批量删除")
    public Result<Boolean> deleteBatch(@RequestBody List<Integer> ids) {
        return Result.ok(robotMeasurePointService.removeByIds(ids));
    }

    /**
     * 查询全部
     */
    @GetMapping("/getAll")
    @ApiOperation(value = "查询全部", notes = "无需传参")
    @OperationLogAnnotation(operModule = "机器人测点表-查询全部", operType = "查询", operContent = "查询全部")
    public Result<List<RobotMeasurePoint>> findAll() {
        return Result.ok(robotMeasurePointService.list());
    }

    /**
     * 根据id查询一个
     */
    @GetMapping("getById/{id}")
    @ApiOperation(value = "根据id查询一个", notes = "传入id")
    @ApiImplicitParam(name = "id", value = "id")
    @OperationLogAnnotation(operModule = "机器人测点表-根据id查询一个", operType = "查询", operContent = "根据id查询一个")
    public Result<RobotMeasurePoint> findOne(@PathVariable Integer id) {
        return Result.ok(robotMeasurePointService.getById(id));
    }

    /**
     * 分页模糊查询
     */
    @PostMapping("/get/page")
    @ApiOperation(value = "分页模糊查询", notes = "传入对应所需参数")
    @ApiImplicitParam(name = "robotMeasurePointPoVo", value = "工具类")
    @OperationLogAnnotation(operModule = "机器人测点表-分页模糊查询", operType = "查询", operContent = "分页模糊查询")
    public Result<Page<RobotMeasurePoint>> findPage(@RequestBody RobotMeasurePointPoVo robotMeasurePointPoVo) {
        LambdaQueryWrapper<RobotMeasurePoint> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(!StringUtil.isNullOrEmpty(robotMeasurePointPoVo.getOrganizationName())
                        , RobotMeasurePoint::getOrganizationName, robotMeasurePointPoVo.getOrganizationName())
                .eq(!StringUtil.isNullOrEmpty(robotMeasurePointPoVo.getStopPointName())
                        , RobotMeasurePoint::getStopPointName
                        , robotMeasurePointPoVo.getStopPointName())
                .eq(!StringUtil.isNullOrEmpty(robotMeasurePointPoVo.getName()),RobotMeasurePoint::getName
                        ,robotMeasurePointPoVo.getName());
        return Result.ok(robotMeasurePointService.page(new Page<>(robotMeasurePointPoVo.getPageNum(), robotMeasurePointPoVo.getPageSize()), lambdaQueryWrapper));
    }
}

